/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "sle_hal_test_entry.h"
#include "sle_loader_hal.h"
#include "sle_ssap_server_hal.h"
#include "sle_hal_errcode.h"

static SleSsapsHalCallbacks *g_sleSsapsHalUtCbs;
static uint16_t g_connectId = 0;
static uint8_t g_serverId = 0;
static SleUuid g_appUuid = {
    .len = 16,
};
static uint16_t g_requestId;

void OnSleHalUtStartServiceCallback(uint8_t serverId, uint16_t serviceHandle, SleHalErrorCode errCode)
{
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] OnSleHalUtStartServiceCallback");
    return;
}

void OnSleHalUtRemoveAllServicesCallback(uint8_t serverId, SleHalErrorCode errCode)
{
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] OnSleHalUtRemoveAllServicesCallback");
    return;
}

void OnSleHalUtReceiveReadRequestCallback(uint8_t serverId, uint16_t connectId, const SsapsReqReadCbParam *reqReadCbPara,
                SleHalErrorCode errCode)
{
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] OnSleHalUtReceiveReadRequestCallback");
    g_requestId = reqReadCbPara->requestId;
    return;
}

void OnSleHalUtReceiveWriteRequestCallback(uint8_t serverId, uint16_t connectId, const SsapsReqWriteCbPara *reqWriteCbPara,
                SleHalErrorCode errCode)
{
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] OnSleHalUtReceiveWriteRequestCallback");
    g_requestId = reqWriteCbPara->requestId;
    return;
}

void OnSleHalUtChangeMtuCallback(uint8_t serverId, const SsapMtuInfo *mtuInfo, SleHalErrorCode errCode)
{
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] OnSleHalUtChangeMtuCallback");
    return;
}

void InitSleSsapsHalTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    ret = InitSleSsapsHal();
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] InitSleSsapsHalTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] InitSleSsapsHalTestLevel0 pass");
}

void DeinitSleSsapsHalTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    ret = DeinitSleSsapsHal();
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] DeinitSleSsapsHalTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] DeinitSleSsapsHalTestLevel0 pass");
}

void SleSsapsHalRegisterCallbacksTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    ret = SleSsapsHalRegisterCallbacks(g_sleSsapsHalUtCbs);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalRegisterCallbacksTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalRegisterCallbacksTestLevel0 pass");
}

void SleSsapsHalAddServerTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    ret = SleSsapsHalAddServer(&g_appUuid, &g_serverId);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalAddServerTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalAddServerTestLevel0 pass");
}

static uint16_t g_serviceHandle;
void SleSsapsHalAddServiceTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    ret = SleSsapsHalAddService(g_serverId, &g_appUuid, true, &g_serviceHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalAddServiceTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalAddServiceTestLevel0 pass");
}

static uint16_t g_propertyHandle;
void SleSsapsHalAddPropertyTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    uint8_t value[10] = {0};
    SsapsPropertyParam propertyParam = {
        .uuid = g_appUuid,
        .permissions = SSAP_PERMISSION_CAN_WRITE,
        .valueLen = 10,
        .value = value,
    };
    ret = SleSsapsHalAddProperty(g_serverId, g_serviceHandle, &propertyParam, &g_propertyHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalAddPropertyTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalAddPropertyTestLevel0 pass");
}

static uint16_t g_descriptorHandle;
void SleSsapsHalAddDescriptorTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    uint8_t value[10] = {0};
    SsapsDescriptorParam descriptorParam = {
        .uuid = g_appUuid,
        .permissions = SSAP_PERMISSION_CAN_READ,
        .operateInd = SSAP_OPERATEIND_BIT_READ,
        .type = SLE_SSAP_DESCRIPTOR_TYPE_USER_DESCRIPTION,
        .valueLen = 10,
        .value = value,
    };
    ret = SleSsapsHalAddDescriptor(g_serverId, g_serviceHandle, g_propertyHandle, &descriptorParam, &g_descriptorHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalAddDescriptorTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalAddDescriptorTestLevel0 pass");
}

void SleSsapsHalStartServiceTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    ret = SleSsapsHalStartService(g_serverId, g_serviceHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalStartServiceTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalStartServiceTestLevel0 pass");
}

void SleSsapsHalSendResponseTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    uint8_t value[10] = {1};
    SsapsSendRspParam sendRspParam = {
        .requestId = g_requestId,
        .valueLen = 10,
        .value = value,
    };
    ret = SleSsapsHalSendResponse(g_serverId, g_serviceHandle, &sendRspParam);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalSendResponseTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalSendResponseTestLevel0 pass");
}

void SleSsapsHalNotifyIndicateTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    uint8_t value[10] = {2};
    SsapsNotifyParam notifyParam = {
        .handle = g_propertyHandle,
        .type = SSAP_PROPERTY_TYPE_VALUE_TYPE,
        .valueLen = 10,
        .value = value,
    };
    ret = SleSsapsHalNotifyIndicate(g_serverId, g_connectId, &notifyParam);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalNotifyIndicateTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalNotifyIndicateTestLevel0 pass");
}

void SleSsapsHalNotifyIndicateByUuidTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    uint8_t value[10] = {2};
    SsapsNotyfyByUuidParam notifyParam = {
        .uuid = g_appUuid,
        .startHandle = 0,
        .endHandle = 100,
        .type = SSAP_PROPERTY_TYPE_VALUE_TYPE,
        .valueLen = 10,
        .value = value,
    };
    ret = SleSsapsHalNotifyIndicateByUuid(g_serverId, g_connectId, &notifyParam);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalNotifyIndicateByUuidTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalNotifyIndicateByUuidTestLevel0 pass");
}

void SleSsapsHalSetMtuInfoTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    SsapMtuInfo mtuInfo = {
        .mtuSize = 300,
        .version = 1,
    };
    ret = SleSsapsHalSetMtuInfo(g_serverId, &mtuInfo);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalSetMtuInfoTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalSetMtuInfoTestLevel0 pass");
}

void SleSsapsHalRemoveAllServicesTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    ret = SleSsapsHalRemoveAllServices(g_serverId);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalRemoveAllServicesTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalRemoveAllServicesTestLevel0 pass");
}

void SleSsapsHalRemoveServerTestLevel0(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    ret = SleSsapsHalRemoveServer(g_serverId);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalRemoveServerTestLevel0 failed(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalRemoveServerTestLevel0 pass");
}

void SleSsapsHalTestLevel0(void)
{
    SLE_UT_LOG("___SleSsapsHalTestLevel0 start");
    InitSleSsapsHalTestLevel0();
    SleSsapsHalRegisterCallbacksTestLevel0();
    SleSsapsHalAddServerTestLevel0();
    SleSsapsHalAddServiceTestLevel0();
    SleSsapsHalAddPropertyTestLevel0();
    SleSsapsHalAddDescriptorTestLevel0();
    SleSsapsHalStartServiceTestLevel0();
    SleSsapsHalSendResponseTestLevel0();
    SleSsapsHalNotifyIndicateTestLevel0();
    SleSsapsHalNotifyIndicateByUuidTestLevel0();
    SleSsapsHalSetMtuInfoTestLevel0();
    SleSsapsHalRemoveAllServicesTestLevel0();
    SleSsapsHalRemoveServerTestLevel0();
    DeinitSleSsapsHalTestLevel0();
    SLE_UT_LOG("___SleSsapsHalTestLevel0 end");
}

void InitSleSsapsHalTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    ret = InitSleSsapsHal();
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] InitSleSsapsHalTestLevel1 failed1(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] InitSleSsapsHalTestLevel1 pass1");
    //测试重复调用
    ret = InitSleSsapsHal();
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] InitSleSsapsHalTestLevel1 failed2(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] InitSleSsapsHalTestLevel1 pass2");
}

void DeinitSleSsapsHalTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    ret = DeinitSleSsapsHal();
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] DeinitSleSsapsHalTestLevel1 failed1(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] DeinitSleSsapsHalTestLevel1 pass1");
    //测试重复调用
    ret = DeinitSleSsapsHal();
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] DeinitSleSsapsHalTestLevel1 failed2(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] DeinitSleSsapsHalTestLevel1 pass2");
}

void SleSsapsHalRegisterCallbacksTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    //测试入参为NULL
    ret = SleSsapsHalRegisterCallbacks(NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_ERR_INVALID_PARAM, "[SleSsapsHalTest][FAILED] SleSsapsHalRegisterCallbacksTestLevel1 failed1(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalRegisterCallbacksTestLevel1 pass1");
    ret = SleSsapsHalRegisterCallbacks(g_sleSsapsHalUtCbs);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalRegisterCallbacksTestLevel1 failed2(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalRegisterCallbacksTestLevel1 pass2");
    // //测试重复调用
    // ret = SleSsapsHalRegisterCallbacks(g_sleSsapsHalUtCbs);
    // SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalRegisterCallbacksTestLevel1 failed3(%d)", ret);
}

void SleSsapsHalAddServerTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    //测试入参为NULL
    ret = SleSsapsHalAddServer(NULL, &g_serverId);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_ERR_INVALID_PARAM, "[SleSsapsHalTest][FAILED] SleSsapsHalAddServerTestLevel1 failed1(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalAddServerTestLevel1 pass1");
    ret = SleSsapsHalAddServer(&g_appUuid, NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_ERR_INVALID_PARAM, "[SleSsapsHalTest][FAILED] SleSsapsHalAddServerTestLevel1 failed2(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalAddServerTestLevel1 pass2");
    
    ret = SleSsapsHalAddServer(&g_appUuid, &g_serverId);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalAddServerTestLevel1 failed3(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalAddServerTestLevel1 pass3");
}

void SleSsapsHalAddServiceTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    //测试入参为NULL
    ret = SleSsapsHalAddService(g_serverId, NULL, true, &g_serviceHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_ERR_INVALID_PARAM, "[SleSsapsHalTest][FAILED] SleSsapsHalAddServiceTestLevel1 failed1(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalAddServiceTestLevel1 pass1");
    ret = SleSsapsHalAddService(g_serverId, &g_appUuid, true, NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_ERR_INVALID_PARAM, "[SleSsapsHalTest][FAILED] SleSsapsHalAddServiceTestLevel1 failed2(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalAddServiceTestLevel1 pass2");
    
    ret = SleSsapsHalAddService(g_serverId, &g_appUuid, true, &g_serviceHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalAddServiceTestLevel1 failed3(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalAddServiceTestLevel1 pass3");
}

void SleSsapsHalAddPropertyTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    //测试入参为NULL
    ret = SleSsapsHalAddProperty(g_serverId, g_serviceHandle, NULL, &g_propertyHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_ERR_INVALID_PARAM, "[SleSsapsHalTest][FAILED] SleSsapsHalAddPropertyTestLevel1 failed1(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalAddPropertyTestLevel1 pass1");
    uint8_t value[10] = {0};
    SsapsPropertyParam propertyParam = {
        .uuid = g_appUuid,
        .permissions = SSAP_PERMISSION_CAN_WRITE,
        .valueLen = 10,
        .value = value,
        .opIndication = SSAP_OPERATEIND_BIT_READ,
    };
    ret = SleSsapsHalAddProperty(g_serverId, g_serviceHandle, &propertyParam, NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_ERR_INVALID_PARAM, "[SleSsapsHalTest][FAILED] SleSsapsHalAddPropertyTestLevel1 failed2(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalAddPropertyTestLevel1 pass2");
    
    ret = SleSsapsHalAddProperty(g_serverId, g_serviceHandle, &propertyParam, &g_propertyHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalAddPropertyTestLevel1 failed3(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalAddPropertyTestLevel1 pass3");
}

void SleSsapsHalAddDescriptorTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    uint8_t value[10] = {0};
    SsapsDescriptorParam descriptorParam = {
        .uuid = g_appUuid,
        .permissions = SSAP_PERMISSION_CAN_READ,
        .operateInd = SSAP_OPERATEIND_BIT_READ,
        .type = SLE_SSAP_DESCRIPTOR_TYPE_USER_DESCRIPTION,
        .valueLen = 10,
        .value = value,
    };
    //测试入参为NULL
    ret = SleSsapsHalAddDescriptor(g_serverId, g_serviceHandle, g_propertyHandle, NULL, &g_descriptorHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_ERR_INVALID_PARAM, "[SleSsapsHalTest][FAILED] SleSsapsHalAddDescriptorTestLevel1 failed1(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalAddDescriptorTestLevel1 1");
    ret = SleSsapsHalAddDescriptor(g_serverId, g_serviceHandle, g_propertyHandle, &descriptorParam, NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_ERR_INVALID_PARAM, "[SleSsapsHalTest][FAILED] SleSsapsHalAddDescriptorTestLevel1 failed2(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalAddDescriptorTestLevel1 pass2");

    ret = SleSsapsHalAddDescriptor(g_serverId, g_serviceHandle, g_propertyHandle, &descriptorParam, &g_descriptorHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalAddDescriptorTestLevel1 failed3(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalAddDescriptorTestLevel1 pass3");
}

void SleSsapsHalStartServiceTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    ret = SleSsapsHalStartService(g_serverId, g_serviceHandle);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalStartServiceTestLevel1 failed(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalStartServiceTestLevel1 pass");
}

void SleSsapsHalSendResponseTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    uint8_t value[10] = {0};
    SsapsSendRspParam sendRspParam = {
        .requestId = g_requestId,
        .valueLen = 10,
        .value = value,
    };
    //测试入参为NULL
    ret = SleSsapsHalSendResponse(g_serverId, g_connectId, NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_ERR_INVALID_PARAM, "[SleSsapsHalTest][FAILED] SleSsapsHalStartServiceTestLevel1 failed1(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalStartServiceTestLevel1 pass1");
    ret = SleSsapsHalSendResponse(g_serverId, g_connectId, &sendRspParam);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalStartServiceTestLevel1 failed2(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalStartServiceTestLevel1 pass2");
}

void SleSsapsHalNotifyIndicateTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    uint8_t value[10] = {2};
    SsapsNotifyParam notifyParam = {
        .handle = g_propertyHandle,
        .type = SSAP_PROPERTY_TYPE_VALUE_TYPE,
        .valueLen = 10,
        .value = value,
    };
    //测试入参为NULL
    ret = SleSsapsHalNotifyIndicate(g_serverId, g_connectId, NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_ERR_INVALID_PARAM, "[SleSsapsHalTest][FAILED] SleSsapsHalNotifyIndicateTestLevel1 failed1(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalNotifyIndicateTestLevel1 pass1");
    ret = SleSsapsHalNotifyIndicate(g_serverId, g_connectId, &notifyParam);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalNotifyIndicateTestLevel1 failed2(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalNotifyIndicateTestLevel1 pass2");
}

void SleSsapsHalNotifyIndicateByUuidTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    uint8_t value[10] = {0};
    SsapsNotyfyByUuidParam notifyParam = {
        .uuid = g_appUuid,
        .startHandle = 0,
        .endHandle = 100,
        .type = SSAP_PROPERTY_TYPE_VALUE_TYPE,
        .valueLen = 10,
        .value = value,
    };
    //测试入参为NULL
    ret = SleSsapsHalNotifyIndicateByUuid(g_serverId, g_connectId, NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_ERR_INVALID_PARAM, "[SleSsapsHalTest][FAILED] SleSsapsHalNotifyIndicateByUuidTestLevel1 failed1(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalNotifyIndicateByUuidTestLevel1 pass1");
    ret = SleSsapsHalNotifyIndicateByUuid(g_serverId, g_connectId, &notifyParam);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalNotifyIndicateByUuidTestLevel1 failed2(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalNotifyIndicateByUuidTestLevel1 pass2");
}

void SleSsapsHalSetMtuInfoTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    SsapMtuInfo mtuInfo = {
        .mtuSize = 300,
        .version = 1,
    };
    //测试入参为NULL
    ret = SleSsapsHalSetMtuInfo(g_serverId, NULL);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_ERR_INVALID_PARAM, "[SleSsapsHalTest][FAILED] SleSsapsHalSetMtuInfoTestLevel1 failed1(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalSetMtuInfoTestLevel1 pass1");
    ret = SleSsapsHalSetMtuInfo(g_serverId, &mtuInfo);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalSetMtuInfoTestLevel1 failed2(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalSetMtuInfoTestLevel1 pass2");
}

void SleSsapsHalRemoveAllServicesTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    ret = SleSsapsHalRemoveAllServices(g_serverId);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalRemoveAllServicesTestLevel1 failed(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalRemoveAllServicesTestLevel1 pass");
}

void SleSsapsHalRemoveServerTestLevel1(void)
{
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    ret = SleSsapsHalRemoveServer(g_serverId);
    SLE_UT_CHECK_AND_PRINT_LOG(ret == SLE_HAL_SUCCESS, "[SleSsapsHalTest][FAILED] SleSsapsHalRemoveServerTestLevel1 failed(%d)", ret);
    SLE_UT_LOG("[SleSsapsHalTest][PASSED] SleSsapsHalRemoveServerTestLevel1 pass");
}

void SleSsapsHalTestLevel1(void)
{
    SLE_UT_LOG("___SleSsapsHalTestLevel1 start");
    InitSleSsapsHalTestLevel1();
    SleSsapsHalRegisterCallbacksTestLevel1();
    SleSsapsHalAddServerTestLevel1();
    SleSsapsHalAddServiceTestLevel1();
    SleSsapsHalAddPropertyTestLevel1();
    SleSsapsHalAddDescriptorTestLevel1();
    SleSsapsHalStartServiceTestLevel1();
    SleSsapsHalSendResponseTestLevel1();
    SleSsapsHalNotifyIndicateTestLevel1();
    SleSsapsHalNotifyIndicateByUuidTestLevel1();
    SleSsapsHalSetMtuInfoTestLevel1();
    SleSsapsHalRemoveAllServicesTestLevel1();
    SleSsapsHalRemoveServerTestLevel1();
    DeinitSleSsapsHalTestLevel1();
    SLE_UT_LOG("___SleSsapsHalTestLevel1 end");
}

SleHalErrorCode InitSleSsapsHalTestEntry(void)
{
    SLE_UT_CHECK_AND_RETURN_RET_LOG(g_sleSsapsHalUtCbs == NULL, SLE_HAL_ERR_COMMON, "[SleSsapsHalTest][FAILED] g_sleSsapsHalUtCbs is not NULL");
    g_sleSsapsHalUtCbs = (SleSsapsHalCallbacks *)malloc(sizeof(SleSsapsHalCallbacks));
    SLE_UT_CHECK_AND_RETURN_RET_LOG(g_sleSsapsHalUtCbs != NULL, SLE_HAL_ERR_DRIVER_OR_SYSTEM,"[SleSsapsHalTest][FAILED] malloc g_sleSsapsHalUtCbs failed");
    g_sleSsapsHalUtCbs->OnSsapsServiceStartedCb = OnSleHalUtStartServiceCallback;
    g_sleSsapsHalUtCbs->OnSsapsAllServiceRemovedCb = OnSleHalUtRemoveAllServicesCallback;
    g_sleSsapsHalUtCbs->OnSsapsRecvReadReqCb = OnSleHalUtReceiveReadRequestCallback;
    g_sleSsapsHalUtCbs->OnSsapsRecvWriteReqCb = OnSleHalUtReceiveWriteRequestCallback;
    g_sleSsapsHalUtCbs->OnSsapsMtuChangeCb = OnSleHalUtChangeMtuCallback;
    uint8_t uuid[UUID_LEN] = {1};
    memcpy(g_appUuid.uuid, uuid, UUID_LEN);
    return SLE_HAL_SUCCESS;
}

SleHalErrorCode DeinitSleSsapsHalTestEntry(void)
{
    if (g_sleSsapsHalUtCbs != NULL) {
        free(g_sleSsapsHalUtCbs);
        g_sleSsapsHalUtCbs = NULL;
    }
    return SLE_HAL_SUCCESS;
}

void SleSsapsHalTestEntry(void)
{
    SLE_UT_LOG("__SleSsapsHalTestEntry start");
    SleHalErrorCode ret = SLE_HAL_ERR_UNKNOWN;
    ret = InitSleSsapsHalTestEntry();
    SLE_UT_CHECK_AND_RETURN(ret == SLE_HAL_SUCCESS);
    SleSsapsHalTestLevel0();
    SleSsapsHalTestLevel1();
    ret = DeinitSleSsapsHalTestEntry();
    SLE_UT_CHECK_AND_RETURN(ret == SLE_HAL_SUCCESS);
    SLE_UT_LOG("__SleSsapsHalTestEntry end");
}
